﻿using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml.Serialization;

namespace iSteam.Sdk.Data
{
    public static class DataSerialise
    {
        public static T Decrypt<T>(string data)
        {
            var serializer = new DataContractJsonSerializer(typeof (T));

            using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(data)))
            {
                var dataObject = serializer.ReadObject(ms);
                return (T)dataObject;
            }
        }

        public static T DeserializeFromXml<T>(string xml)
        {
            T result;
            var ser = new XmlSerializer(typeof(T));
            using (var tr = new StringReader(xml))
            {
                result = (T)ser.Deserialize(tr);
            }
            return result;
        }
    }
}
